package com.common;

import org.aspectj.weaver.ast.Var;
import org.junit.validator.PublicClassValidator;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONCreator;
import com.model.Rsltobj;

public class Cmn {
	public void ps(String str){
		System.out.println(str);
	}
	
	public String createok(String cd,String json,String msg){
		
		Rsltobj rsltobj=new Rsltobj();
		
		String cd_nw=createcode(cd);
		rsltobj.setCode(cd_nw);
		JSONObject job= JSON.parseObject(json);
		rsltobj.setData(job);
		rsltobj.setMsg(msg);
		
		return JSON.toJSONString(rsltobj);
		
	
	}
	
	public String createcode(String cd){
		String code="";
		if(cd=="ok"){
			code="A00000";
		}else{
			int asc=0;
			for(int i=0;i<cd.length();i++){
				char c=cd.charAt(i);
				asc=asc+Integer.valueOf(c);
			}
			int bits=String.valueOf(asc).length();
			
			int zeronum=0;
			if(bits<=5){zeronum=5-bits;}

			String zero="";
			for(int i=0;i<zeronum;i++){
				zero=zero+"0";
			}
			code="A"+zero+asc;
		}
		return code;
	}
	
}
